<?php
class SalesMgr
{
	private $dbc;

	public function __construct($dbc = null)
	{
		if (isset($dbc))
		{
			$this->dbc = $dbc;
		}
	}

	public function getSaleProducts()
	{
		$_products=array();
		$q =    'SELECT sa.price AS saleprice,ncp.id
			FROM sales AS sa 
			INNER JOIN product AS ncp ON (sa.product_id=ncp.id AND (ncp.typecode =2 OR ncp.typecode=4) )
			WHERE  ((NOW() BETWEEN sa.start_date AND sa.end_date) OR (NOW() > sa.start_date AND sa.end_date IS NULL) )';

	 $r = mysqli_query($this->dbc, $q);
		$repository=BO::getProductBORepository();
		while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{
			
			$productbo=$repository->getProductBO($row['id']);
			$_product=array();
			$_product['bo']= $productbo;	
			$_product['name']= $productbo->getName() ;			
			$_product['image']= $productbo->getImage() ;
			$_product['price']= $productbo->getPrice();
			$_product['id']= $row['id'] ;
			$_product['saleprice']= $row['saleprice'] ;

			$_products[]=$_product;
		}

		mysqli_free_result ($r);

		return $_products;
	}

}